package com.fdm.model.DAO;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import com.fdm.model.accounts.AccountFactory;
import com.fdm.model.accounts._Account;
import com.fdm.model.exceptions.AccountCreationException;
import com.fdm.model.exceptions.BankManagerException;
import com.fdm.model.exceptions.DAOException;

public class RSAccountBuilder 
{
	public _Account buildAccount(ResultSet rs) 
			throws DAOException
	{
		if(rs==null) return null;
		try {
			Map<String,Object> parameters = new HashMap<String,Object>();
			parameters.put("accountType", rs.getString("ACCOUNTTYPE"));
			parameters.put("name", rs.getString("ACCOUNTNAME"));
			parameters.put("accountNumber",Integer.parseInt(rs.getString("ACCOUNTNUMBER")));
			parameters.put("balance",Double.parseDouble(rs.getString("BALANCE")));
			parameters.put("interestRate",Double.parseDouble(rs.getString("INTERESTRATE")));
			parameters.put("overDraftLimit",Double.parseDouble(rs.getString("OVERDRAFTLIMIT")));
		
			return new AccountFactory().createAccount(rs.getString("ACCOUNTTYPE")
					, parameters);
		} catch (AccountCreationException e) {
		} catch (BankManagerException e) {
		} catch (SQLException e) {
		}
		return null;
	} 
}
